<?php

namespace common\models\db\tables;

use Yii;

/**
 * This is the model class for table "{{%docu}}".
 *
 * @property string $id
 * @property string $uuid
 * @property int $type 文档类型
 * @property int $status 状态
 * @property int $created_at
 * @property string $created_by
 * @property int $updated_at
 * @property string $updated_by
 * @property string $title
 * @property string $pre_logo
 * @property string $desc
 * @property string $look_pwd 浏览密码
 *
 * @property User $createdBy
 * @property User $updatedBy
 * @property DocuBody $docuBody
 * @property DocuComment[] $docuComments
 * @property DocuTag[] $docuTags
 * @property Tag[] $tags
 */
class Docu extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%docu}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['uuid', 'created_at', 'created_by', 'updated_at', 'updated_by', 'title'], 'required'],
            [['type', 'status', 'created_at', 'created_by', 'updated_at', 'updated_by'], 'integer'],
            [['uuid'], 'string', 'max' => 32],
            [['title', 'pre_logo', 'desc'], 'string', 'max' => 191],
            [['look_pwd'], 'string', 'max' => 20],
            [['created_by'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['created_by' => 'id']],
            [['updated_by'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['updated_by' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'uuid' => Yii::t('app', 'Uuid'),
            'type' => Yii::t('app', '文档类型'),
            'status' => Yii::t('app', '状态'),
            'created_at' => Yii::t('app', 'Created At'),
            'created_by' => Yii::t('app', 'Created By'),
            'updated_at' => Yii::t('app', 'Updated At'),
            'updated_by' => Yii::t('app', 'Updated By'),
            'title' => Yii::t('app', 'Title'),
            'pre_logo' => Yii::t('app', 'Pre Logo'),
            'desc' => Yii::t('app', 'Desc'),
            'look_pwd' => Yii::t('app', '浏览密码'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUpdatedBy()
    {
        return $this->hasOne(User::className(), ['id' => 'updated_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuBody()
    {
        return $this->hasOne(DocuBody::className(), ['docu_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuComments()
    {
        return $this->hasMany(DocuComment::className(), ['docu_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuTags()
    {
        return $this->hasMany(DocuTag::className(), ['docu_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTags()
    {
        return $this->hasMany(Tag::className(), ['id' => 'tag_id'])->viaTable('{{%docu_tag}}', ['docu_id' => 'id']);
    }
}
